package anthology.daily_question._25_02;
//https://leetcode.cn/problems/number-of-even-and-odd-bits/description/?envType=daily-question&envId=2025-02-20
public class _2595奇偶位数 {
    class Solution {
        public int[] evenOddBit(int n) {
            int even = 0, odd = 0;
            int index = 0; // 用于跟踪当前位的下标

            while (n > 0) {
                if ((n & 1) == 1) { // 检查最低位是否为1
                    if (index % 2 == 0) {
                        even++;
                    } else {
                        odd++;
                    }
                }
                n >>= 1; // 右移一位，相当于去掉最低位
                index++; // 增加下标计数
            }

            return new int[]{even, odd};
        }
    }
    class Solution2 {
        public int[] evenOddBit(int n) {
            int[] ans = new int[2];
            for (int i = 0; n > 0; n >>= 1) {
                ans[i] += n & 1;
                i ^= 1; // 切换奇偶
            }
            return ans;
        }
    }
}
